package com.TestDemo.Test2;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/16/9:16
 * @Description:
 * @Target: 一个随机的01-99的数字,100个01-99的数字 先输出第一个数字,再输出100个数字
 */
public class 模仿彩票 {
    public static void main(String[] args) {

        int[] ints1 = RandomInt(1, 1, 99);
        String ss = "中奖金额:";
        if (ints1[0]<10){
            System.out.println("中奖号码:0"+ints1[0]);
        }else {
            System.out.println("中奖号码:"+ints1[0]);
        }
        System.out.println("01 02 03 04 05 06 07 08 09 10 RMB");
        System.out.println("---------------------------------");
        int[] ints2 = RandomRMB(10,10);


        for (int i = 0; i < 10; i++) {
            int[] ints = RandomInt(10, 1, 99);
            for (int anInt : ints) {
                if (anInt==ints1[0]){
                    ss=ss+ints2[i]+" ";
                }
                if (anInt<10){
                    System.out.print("0"+anInt+ " ");
                }else {
                    System.out.print(anInt+ " ");
                }
            }
            System.out.println(ints2[i]);
        }


        if ("中奖金额:".equals(ss)){
            System.out.println("木有中奖!!!");
        }else {
            System.out.print("恭喜中奖!!!    ");
            System.out.println(ss);
        }

    }



    public static int[] RandomRMB(int len,int n){
        int arr1[] = new int[]{10,20,30,40,50,60,70,80,90,100,200,500,1000,5000,100000,500000,400000};
        int arr[] = RandomInt(len,0,arr1.length-1);
        HashSet set = new HashSet();

        int i = 0;
        while (i<len){
            arr[i] = arr1[arr[i]];
            if (!set.contains(arr[i])){
                set.add(arr[i]);
                i++;
            }
        }
        if (!set.contains(n)){
            int[] ints = RandomInt(1, 0, len-1);
            arr[ints[0]] = n;
        }
        return arr;
    }

    public static int[] RandomInt(int len,int min,int max){
        int arr[] = new int[len];
        HashSet set = new HashSet();
        int i = 0;
        while (i<len){
            arr[i] = min + (int)(Math.random()*(max-min+1));
            if (!set.contains(arr[i])){
                set.add(arr[i]);
                i++;
            }
        }
        return arr;
    }

}
